package sliver.action.shop.ajax;

import java.io.Writer;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import sliver.entity.Vip;
import sliver.service.shop.vip.VipLevelService;

import com.alibaba.fastjson.JSON;
import com.opensymphony.xwork2.ActionSupport;

@Scope("prototype")
@Controller("shop.ajax.queryVipLevelAction")
public class QueryVipLevelAction extends ActionSupport{

	private static final long serialVersionUID = -1899826803562606610L;
	
	private Integer shopperId;
	
	@Autowired
	private VipLevelService vipLevelService; 
	
	public QueryVipLevelAction(){
		
	}

	public Integer getShopperId() {
		return shopperId;
	}

	public void setShopperId(Integer shopperId) {
		this.shopperId = shopperId;
	}
	
	@Override
	public String execute() throws Exception {
		
		List<Vip> vips = vipLevelService.listVipLevels(shopperId);
		 
		String json = JSON.toJSONString(vips);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json;charset=utf-8");
		
		Writer writer = response.getWriter();
		writer.write(json);
		writer.flush();
		
		return null;
	}
}
